// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    datarow:10,    
    datalow:10,    
    listdata:[],
    modellist:null,
    array: ['孙雪荣老师', '刘新光老师', '黄遵楠老师', '李老师'],
    index: 0,
  },
  bindPickerChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value
    })
  },

  showModal(e) {
    this.setData({
      modellist: e.currentTarget.dataset.item,
      modalName: e.currentTarget.dataset.target
    })
  },
  hideModal() {
    this.setData({
      modalName: null
    })
  },
  loops(){
    this.hideModal();
    let appsto = this.data.modellist;
    appsto['treach'] = this.data.array[this.data.index];
    let datas = JSON.stringify(appsto);
    wx.navigateTo({
      url: '/pages/logs/logs?item='+datas,
    })
  },
  
  //渲染列表
  sortList(){
    const row = this.data.datarow ;
    const low = this.data.datalow ;
    wx.cloud.callFunction({name:'getledata'}).then(res=>{
      console.log(res);
      let setting = [];
      for(let i= 0;i<row ;i++){
        let set = [];
        for(let j=0;j<low ;j++){
          let rows = {}
          for(let m= 0;m<res.result.data.length;m++){
            if(i == res.result.data[m].chiose_row  && j == res.result.data[m].chiose_low ){
              rows['type'] = true;
              rows['login_inf'] = res.result.data[m];
              rows['row'] = i;
              rows['low'] = j;
              break;
             }else{
              rows['type'] = false;
              rows['login_inf'] = ''
              rows['row'] = i;
              rows['low'] = j;
             }
          }
          set.push(rows);
        };
        setting.push(set);
      }
      this.setData({listdata:setting});
    }).catch(res=>{
      console.log(res);
    })
  },
 
  onLoad() {
    this.sortList();
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
     this.sortList();
  },
  takePhoto() {
    const ctx = wx.createCameraContext()
    ctx.takePhoto({
      quality: 'high',
      success: (res) => {
        this.setData({
          src: res.tempImagePath
        })
        wx.previewImage({
          current: res.tempImagePath, // 当前显示图片的http链接
          urls: [res.tempImagePath] // 需要预览的图片http链接列表
        })
      }
    })
  }
})

